package com.zhangkunhao.notes.view;

import com.zhangkunhao.notes.controller.AdministratorMenuListener;
import com.zhangkunhao.notes.controller.CancelListener;

import java.awt.*;

import javax.swing.*;

/**
 * 管理员菜单界面
 *
 * @author 张坤浩
 */
public class AdministratorsMenuView extends JFrame {
    private JFrame openFrame;

    public AdministratorsMenuView(JFrame openFrame) {
        this.openFrame = openFrame;
    }

    public AdministratorsMenuView() {
    }

    public void initComponents() {
        setFont(new Font(Font.DIALOG, Font.PLAIN, 18));

        JButton button1 = new JButton();
        JButton button2 = new JButton();
        JButton button3 = new JButton();
        JButton button4 = new JButton();
        JButton button5 = new JButton();
        JButton button6 = new JButton();
        JButton button7 = new JButton();
        //======== this ========
        setTitle("欢迎你，管理员");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);
        //---- button1 ----
        button1.setText("查询所有用户信息");
        contentPane.add(button1);
        button1.setBounds(40, 25, 150, button1.getPreferredSize().height);

        //---- button2 ----
        button2.setText("发布各种积攒功德的活动");
        contentPane.add(button2);
        button2.setBounds(40, 70, 155, 30);

        //---- button3 ----
        button3.setText("查询所有活动信息");
        contentPane.add(button3);
        button3.setBounds(40, 115, 155, 30);

        //---- button4 ----
        button4.setText("搜索指定用户");
        contentPane.add(button4);
        button4.setBounds(35, 165, 155, 30);

        //---- button5 ----
        button5.setText("批量发布功德活动");
        contentPane.add(button5);
        button5.setBounds(40, 220, 155, 30);

        //---- button6 ----
        button6.setText("查看某个⽤户的功德消耗、获取情况");
        contentPane.add(button6);
        button6.setBounds(25, 275, 340, 55);

        button7.setText("退出");
        contentPane.add(button7);
        button7.setBounds(25, 375, 240, 55);

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for (int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        this.setVisible(true);
        pack();
        setLocationRelativeTo(getOwner());
        //按钮绑定管理员页面的事件
        AdministratorMenuListener administratorMenuListener = new AdministratorMenuListener();
        button1.addActionListener(administratorMenuListener);
        button2.addActionListener(administratorMenuListener);
        button3.addActionListener(administratorMenuListener);
        button4.addActionListener(administratorMenuListener);
        button5.addActionListener(administratorMenuListener);
        button6.addActionListener(administratorMenuListener);
        //按钮绑定页面回退的事件
        button7.addActionListener(new CancelListener(openFrame, this));
    }
}
